<?php

//获取用户点击的散列
//{"code":""}
//$data = json_decode(file_get_contents("php://input"));

require_once ("./getUA.php");
require_once ("./read.php");
//$data = "3038267725@qq.com";
$ua = new getUA('');
//拿到用户访问邮箱里的链接的UA数据
$ua = $ua->data_status();

//拿到用户连接上面的recover_code数据
$recover_code = $_GET['recover_code'];

//对user_activation_key进行索引,得到一个数组
$activation_key = $post->Search_option("user_activation_key",$recover_code);
var_dump($activation_key);
if ($activation_key){
    $user_id = $activation_key['ID'];
    //匹配用户的UA数据
    $status = $post->Search_UA($user_id);
    if ($status){
        //进行时间的匹配
        $time = strtotime($status['update_time']);
        $now_time = time();
        if ($now_time - $time <= 600){
            $bool = ($status['OS']==$ua['OS'])&& ($status['ip']==$ua['ip'])&&($status['browser']==$ua['browser']);
            if ($bool){
                //信息完全匹配，修改密码
                $passwd = json_decode(file_get_contents("php://input"));//可能因为GET而无法获取--4.3号留--sinmu
                $res_passwd = $post->UpdatePasswd($activation_key['user_email'],md5($passwd->password));
                var_dump($res_passwd);
                return $res_passwd;


            }else{
                $result = json_encode(
                    array(
                        'status'=>201,
                        'msg'=>"UA信息不匹配",
                    ),
                    JSON_UNESCAPED_UNICODE
                );
                var_dump($result);
                return $result;
            }
        }else{
            $result = json_encode(
                array(
                    'status'=>201,
                    'msg'=>"链接超时",
                ),
                JSON_UNESCAPED_UNICODE
            );
            var_dump($result);
            return $result;
        }
    }else{
        $result = json_encode(
            array(
                'status'=>201,
                'msg'=>'用户UA数据有误',
            ),
            JSON_UNESCAPED_UNICODE
        );
        var_dump($result);
        return $result;
    }

}else{
    $result = json_encode(
        array(
            'status'=>201,
            'msg'=>'404,链接无效',//链接无效
        ),
        JSON_UNESCAPED_UNICODE
    );
    var_dump($result);
    return $result;
}



